package controller.day04;

import entity.User;
import service.UserService;
import service.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "GetAllUserServlet", value = "/GetAllUserServlet")
public class GetAllUserServlet extends HttpServlet {
    UserService userService = new UserServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1. 调用service  查询所有用户
        List<User> userList  = userService.findAll();

        //2. 数据绑定request
        request.setAttribute("userList",userList);

        //3. 页面跳转
        request.getRequestDispatcher("/day04/allUser.jsp").forward(request,response);
    }
}

